<template>
  <div>
    <!-- 注册页 -->

    <!-- 导航栏 -->
    <van-nav-bar
      class="bac"
      title="注册"
      left-arrow
      @click-left="$router.back()"
    />
    <!-- Form 表单 -->
    <van-form @submit="register">
      <van-field
        v-model="regList.phone"
        name="手机号"
        label="手机号"
        placeholder="请输入手机号"
        :rules="[{ required: true, message: '请输入手机号' }]"
      />
      <van-field
        v-model="regList.nickname"
        name="昵称"
        label="昵称"
        placeholder="请输入昵称"
        :rules="[{ required: true, message: '请输入昵称' }]"
      />
      <van-field
        v-model="regList.password"
        type="password"
        name="密码"
        label="密码"
        placeholder="密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <div class="register">
        <van-button round block type="info" native-type="submit"
          >注册</van-button
        >
      </div>
    </van-form>
  </div>
</template>

<script>
// 引入轻提示
import { Toast } from "vant";
import { register } from "../util/axios";
export default {
  data() {
    return {
      regList: {
        phone: "", //手机号
        nickname: "", //昵称
        password: "" //密码
      }
    };
  },
  methods: {
    //封装一个注册事件
    register() {
      register(this.regList).then(res => {
        // console.log(res, "响应");
        if (res.code == 200) {
          //注册成功之后跳转到 登录页面
          this.$router.push("/login");
          Toast.success(res.msg);
        } else {
          Toast.fail(res.msg);
        }
      });
    }
  }
};
</script>

<style lang="" scoped>
.bac {
  background: #ff6040;
}
.register {
  margin-top: 117px;
}
</style>
